const state = {
  visitedViews: [],
  cachedViews: [{name:'Dashboard',path:'/dashboard',fixed:true} ,{name:'Documentation',path:'/documentation',fixed:true}]
}
const mutations={
  ADD_CACHED_VIEW(state,view){
    state.visitedViews=state.cachedViews 
  },
  ADD_VISITED_VIEW(state,view){     
    if(!state.visitedViews.some(v=> v.name==view.name)){   
      state.visitedViews.push({name:view.name,path:view.path})
    }
  },
  DEL_VIEW(state,view){
    let index=state.visitedViews.findIndex(v=>v.name==view.name)
    console.log(index,'index');   
    state.visitedViews.splice(index,1)
  }
}
const actions={
  initView({commit},view){   
    commit('ADD_CACHED_VIEW',view)
    commit('ADD_VISITED_VIEW',view)
  },
  addView({dispatch,state},view){
    dispatch('addVisitedView', view)
  },
  addVisitedView({commit},view){
    commit('ADD_VISITED_VIEW',view)
  },
  delView({commit},view){
    return new Promise((resove)=>{
      commit('DEL_VIEW',view)
      resove(view)
    })
  }
}
export default {
  namespaced: true,
  state,
  mutations,
  actions
}